﻿using System;

namespace MadLibrary.Text
{
    /// <summary>
    /// FlatFile reader interface
    /// </summary>
    public interface IFlatFileReader
    {
        /// <summary>
        /// Record size
        /// </summary>
        int RecordSize { get; }

        /// <summary>
        /// Source string
        /// </summary>
        string Source { get; }

        /// <summary>
        /// Initialize source to read
        /// </summary>
        /// <param name="source"></param>
        void Initialize(string source);

        /// <summary>
        /// Read boolean type
        /// </summary>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length to read.</param>
        /// <returns>Boolean type value</returns>
        bool ReadBool(int start, int length);

        /// <summary>
        /// Read date
        /// </summary>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length.</param>
        /// <returns>nullable DateTime value</returns>
        DateTime? ReadDate(int start, int length);

        /// <summary>
        /// Read decimal
        /// </summary>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length.</param>
        /// <param name="decimalPlaces">Decimal places</param>
        /// <param name="signEnum">+/- sign</param>
        /// <returns>Decimal value</returns>
        decimal ReadDecimal(int start, int length, int decimalPlaces, FlatFile.SignPosition signEnum);

        /// <summary>
        /// Read double
        /// </summary>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length.</param>
        /// <param name="decimalPlaces">Decimal places</param>
        /// <param name="signEnum">+/- sign</param>
        /// <returns>Double value</returns>
        double ReadDouble(int start, int length, int decimalPlaces, FlatFile.SignPosition signEnum);

        /// <summary>
        /// Read integer
        /// </summary>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length.</param>
        /// <returns>Int value</returns>
        int ReadInteger(int start, int length);

        /// <summary>
        /// Read integer
        /// </summary>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length.</param>
        /// <param name="signEnum">+/- sign</param>
        /// <returns>Int value</returns>
        int ReadInteger(int start, int length, FlatFile.SignPosition signEnum);

        /// <summary>
        /// Read long
        /// </summary>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length.</param>
        /// <returns>Long value</returns>
        long ReadLong(int start, int length);

        /// <summary>
        /// Read long
        /// </summary>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length.</param>
        /// <param name="signEnum">+/- sign</param>
        /// <returns>Long value</returns>
        long ReadLong(int start, int length, FlatFile.SignPosition signEnum);

        /// <summary>
        /// Read short
        /// </summary>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length.</param>
        /// <returns>Short value</returns>
        short ReadShort(int start, int length);

        /// <summary>
        /// Read short
        /// </summary>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length.</param>
        /// <param name="signEnum"></param>
        /// <returns>Short value</returns>
        short ReadShort(int start, int length, FlatFile.SignPosition signEnum);

        /// <summary>
        /// Read string
        /// </summary>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length.</param>
        /// <returns>String value</returns>
        string ReadString(int start, int length);
    }

    /// <summary>
    /// FlatFile writer interface
    /// </summary>
    public interface IFlatFileWriter
    {
        /// <summary>
        /// Lenght
        /// </summary>
        /// <returns>Current lenght of writen data</returns>
        int Length();

        /// <summary>
        /// Get data
        /// </summary>
        /// <returns>Current writen data.</returns>
        string GetData();

        /// <summary>
        /// Write bool
        /// </summary>
        /// <param name="data">Input data</param>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length</param>
        void WriteBool(bool? data, int start, int length);

        /// <summary>
        /// Write datetime - nullable
        /// </summary>
        /// <param name="data">Input data</param>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length</param>
        /// <param name="dateFormat">Date format</param>
        void WriteDate(DateTime? data, int start, int length, string dateFormat);

        /// <summary>
        /// Write decimal with sign position
        /// </summary>
        /// <param name="data">Input data</param>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length</param>
        /// <param name="decimalPlaces">Decimal places</param>
        /// <param name="signEnum">+/- sign</param>
        void WriteDecimal(decimal? data, int start, int length, short decimalPlaces, FlatFile.SignPosition signEnum);

        /// <summary>
        /// Write double with sign position
        /// </summary>
        /// <param name="data">Input data</param>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length</param>
        /// <param name="decimalPlaces">Decimal places</param>
        /// <param name="signEnum">+/- sign</param>
        void WriteDouble(double? data, int start, int length, short decimalPlaces, FlatFile.SignPosition signEnum);

        /// <summary>
        /// Write integer
        /// </summary>
        /// <param name="data">Input data</param>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length</param>
        void WriteInteger(int? data, int start, int length);

        /// <summary>
        /// Write integer with sign position
        /// </summary>
        /// <param name="data">Input data</param>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length</param>
        /// <param name="signEnum">+/- sign</param>
        void WriteInteger(int? data, int start, int length, FlatFile.SignPosition signEnum);

        /// <summary>
        /// Write long
        /// </summary>
        /// <param name="data">Input data</param>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length</param>
        void WriteLong(long? data, int start, int length);

        /// <summary>
        /// Write long with sign position
        /// </summary>
        /// <param name="data">Input data</param>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length</param>
        /// <param name="signEnum">+/- sign</param>
        void WriteLong(long? data, int start, int length, FlatFile.SignPosition signEnum);

        /// <summary>
        /// Write short
        /// </summary>
        /// <param name="data">Input data</param>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length</param>
        void WriteShort(short? data, int start, int length);

        /// <summary>
        /// Write short with sign position
        /// </summary>
        /// <param name="data">Input data</param>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length</param>
        /// <param name="signEnum">+/- sign</param>
        void WriteShort(short? data, int start, int length, FlatFile.SignPosition signEnum);

        /// <summary>
        /// Write string
        /// </summary>
        /// <param name="data">Input data</param>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length</param>
        void WriteString(string data, int start, int length);

        /// <summary>
        /// Write string
        /// </summary>
        /// <param name="data">Input data</param>
        /// <param name="start">Starting position in string. (zero based)</param>
        /// <param name="length">Length</param>
        /// <param name="padSide">Pad side</param>
        void WriteString(string data, int start, int length, FlatFile.PadSide padSide);       
    }
}
